﻿layui.use(function () {
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;
    form.on('submit(formSubmit)', function (data) {
        var field = data.field;
        console.log(field);//field.products
        // 显示填写结果，仅作演示用
        //debugger
        $.ajax({
            url: '../RawMaterial/RawMaterAdd',
            type: 'post',
            data: { data: JSON.stringify(field), token: localStorage.getItem("token") },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(field);
                console.log(res);
                if (res.data == 1) {
                    layer.alert("添加成功");
                    location.href = '/RawMaterial/RawMaterialShow'
                } else {
                    layer.alert("添加失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });
})